package Text_88;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class Code {

	public static void main(String[] args) throws IOException {
		 //接收数据
        //创建对象
        DatagramSocket ds = new DatagramSocket(10086);
        byte[] bytes1 = new byte[1024];
        //接收数据的包
        DatagramPacket dp1 = new DatagramPacket(bytes1, bytes1.length);
        ds.receive(dp1);
        //解析数据包
        byte[] data = dp1.getData();
        int length = dp1.getLength();
        InetAddress address = dp1.getAddress();
        int port = dp1.getPort();
        System.out.println("接收到数据"+new String(data,0,length));
        System.out.println("该数据是从"+address+"这台电脑中的"+port+"这个端口发出的");
        //释放资源
        ds.close();

	}

}
